package com.huanlis.workflow.server.engine;

import com.huanlis.core.Action;
import com.huanlis.core.BaseDomain;
import com.huanlis.workflow.server.domain.FlowEntity;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class FlowRepository {

    private final Map<String, CompletableFuture<? extends BaseDomain>> flowRepository = new ConcurrentHashMap<>();

    public void registerFlow(String flowId, List<Action<? extends BaseDomain, ? extends BaseDomain>> actions) {
        CompletableFuture<BaseDomain> completableFuture = new CompletableFuture<BaseDomain>() {
        };
        flowRepository.put(flowId, completableFuture);
    }

    public void registerFlow(FlowEntity flowEntity) {
        CompletableFuture<BaseDomain> completableFuture = new CompletableFuture<BaseDomain>() {
        };
    }

    public String executeFlow(String flowId, BaseDomain input) {
        CompletableFuture<BaseDomain> completableFuture = (CompletableFuture<BaseDomain>) flowRepository.get(flowId);
        boolean complete = completableFuture.complete(input);

        return complete ? "success" : "failed";

    }
}
